1882C - Card Game - CodeForces Solution


greedy

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <vector>
#define pb push_back
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define ll  long long int 
#define gt greater<ll>()
#define ff first
#define ss second
#define pi acos(-1)
#define ull unsigned long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define  mod 1000000007;
#define bi_one(n)      __builtin_popcount(n)
#define str(a)          a.begin(),a.end()
#define mem(a,b)        memset(a, b, sizeof(a) )
#define max_ele(a,n)    *max_element(a,a+n)
#define min_ele(a,n)    *min_element(a,a+n)
#define fio()                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define sp(n) fixed << setprecision(n)
#define Erase(s) s.erase(unique(s.begin(), s.end()), s.end())
#define fn0 for (i = 0; i < n; i++)
#define fn1 for(i=1; i<=n; i++)
#define upper(v,val) upper_bound(v.begin(), v.end(), val)-v.begin()
#define lower(v,val) lower_bound(v.begin(), v.end(), val)-v.begin()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*(b/gcd(a,b)))
using namespace std;
 ll vv[200007];
 ll modd= 998244353;
const int N=2e5+5;
vector<int> g[N];
bool vis[N];
int n,m,ans=0;
//vector<ll>v,vv;
map<ll,ll>mp;
void print(vector<ll> &v)
{
    for (ll i = 0; i < v.size(); i++)
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

  void fact()
  {
    vv[0]=1;
    for(ll i=1; i<=200005; i++)
    {
        vv[i]=(vv[i-1]*i)%modd;
     }
 }
void solution()
{
    ll n, m,sq,r=0,q, k = 0,l=0, i, j, a=0, b=0,d=0, c = 0, d1 = 0, sum = 0;
    string s,s1="";
    cin>>n;
    vector<ll> v1,v0,v;

    fn0
    {
        cin>>a;
        v.pb(a);
        if(a>=0)
            sum+=a;
    }
    if(v[0]>=0 || n==1 || v[1]<0)
    {
        cout<<sum<<endl;
        return;
    }
    if(v[1]> abs(v[0]))
    {
        sum+=v[0];
        cout<<sum<<endl;
        return;
    }
    sum-=v[1];
    cout<<sum<<endl;
    return;
}

int main()
{
    fio();
   // okk();
    int tt = 1;
   cin >> tt;
  //fact();
   // int x=1;
  
  
    while (tt--)
    {
        //cout<<"Case "<<x<< ": ";
        solution();
        //x++;
    }
}


Comments

Submit
0 Comments
More Questions

1478A - Nezzar and Colorful Balls
1581B - Diameter of Graph
404A - Valera and X
908A - New Year and Counting Cards
146A - Lucky Ticket
1594C - Make Them Equal
1676A - Lucky
1700B - Palindromic Numbers
702C - Cellular Network
1672C - Unequal Array
1706C - Qpwoeirut And The City
1697A - Parkway Walk
1505B - DMCA
478B - Random Teams
1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64